<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>闭包访问</title>
</head>
<body>
    
</body>
</html>
<script>
    //访问器的优先级高于属性的访问
    let data = {
        name : 'houdunren.com',
        age : 55
    };
    for(const [key,value] of Object.entries(data)){
        observer(data,key,value);
    }

    function observer(data,key,v){
        Object.defineProperty(data,key,{
            get(){
                console.log('get....');
                return v;
            },
            set(newValue){
                console.log('set....')
                v = newValue;
            }
        });
    }
    // console.log(data.name);
    data.name = '后盾人';
    console.dir(data.name);

</script>